package fs.ryj;

import java.util.HashSet;
import java.util.Set;


public class UserDao {
    Set<User> users =new HashSet<>();
    public UserDao(){
		//这种测试数据在测试代码中去写，想办法set或者add进来
        users.add(new User(1,"张三"));
        users.add(new User(2,"李四"));
        users.add(new User(3,"王五"));
        users.add(new User(4,"taimukang"))
    }
    public Set<User> getAll(){
        return users;
    }
    public boolean deleteUser(User user){
        boolean flag = false;
        for(User user1:users){
            if (user1.equals(user)){
                flag=true;
            }
        }
        if (flag){
            users.remove(user);
        }else {
            System.out.println("集合中查无此人");
        }
        return flag;
    }
     public boolean add(User user){
        boolean flag=false;
        for(User user1:users){
            if (user1.equals(user)){
                flag = true;
                break;
            }
        }
        if (flag==true){
            System.out.println("此人已存在");
        }else {
            users.add(user);
            System.out.println("添加成功");
        }
        return flag;
     }

     public boolean update(User user){
        boolean flag = false;
        for (User user1:users){
            if (user1.getUserId()==user.getUserId()){
                user1.setName(user.getName());
                flag=true;
            }
        }if (flag){
             System.out.println("修改成功");
         }else {
             System.out.println("集合中无此人");
         }
        return flag;
     }
}
